package org.framework.lazy.cloud.network.heartbeat.server.standalone.application.impl;

import jakarta.annotation.Resource;
import org.framework.lazy.cloud.network.heartbeat.server.properties.ServerNodeProperties;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.LazyNettyServerPermeatePortPoolApplication;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.assembler.NettyServerVisitorDTOAssembler;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.command.lazy.netty.server.permeate.port.pool.*;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.dto.LazyNettyServerVisitorDTO;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.server.permeate.port.pool.LazyNettyServerPermeatePortPool;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.server.permeate.port.pool.LazyNettyServerPermeatePortPoolRepository;
import org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyApplicationImpl;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.wu.framework.lazy.orm.web.plus.stereotype.LazyApplication;
import org.wu.framework.web.response.Result;

import java.util.List;
import java.util.stream.Collectors;

/**
 * describe 服务端提前开放出来的端口
 *
 * @author Jia wei Wu
 * @date 2024/01/16 02:21 下午
 * @see DefaultDDDLazyApplicationImpl
 **/
@LazyApplication
public class LazyNettyServerPermeatePortPoolApplicationImpl implements LazyNettyServerPermeatePortPoolApplication {

    @Resource
    LazyNettyServerPermeatePortPoolRepository lazyNettyServerPermeatePortPoolRepository;

    @Resource
    ServerNodeProperties serverNodeProperties;

    /**
     * describe 新增服务端提前开放出来的端口
     *
     * @param lazyNettyServerPermeatePortPoolStoryCommand 新增服务端提前开放出来的端口
     * @return {@link Result<   LazyNettyServerPermeatePortPool   >} 服务端提前开放出来的端口新增后领域对象
     * @author Jia wei Wu
     * @date 2024/01/16 02:21 下午
     **/

    @Override
    public Result<LazyNettyServerPermeatePortPool> story(LazyNettyServerPermeatePortPoolStoryCommand lazyNettyServerPermeatePortPoolStoryCommand) {
        LazyNettyServerPermeatePortPool lazyNettyServerPermeatePortPool = NettyServerVisitorDTOAssembler.INSTANCE.toNettyServerVisitor(lazyNettyServerPermeatePortPoolStoryCommand);
        return lazyNettyServerPermeatePortPoolRepository.story(lazyNettyServerPermeatePortPool);
    }

    /**
     * describe 批量新增服务端提前开放出来的端口
     *
     * @param lazyNettyServerPermeatePortPoolStoryCommandList 批量新增服务端提前开放出来的端口
     * @return {@link Result<List<  LazyNettyServerPermeatePortPool  >>} 服务端提前开放出来的端口新增后领域对象集合
     * @author Jia wei Wu
     * @date 2024/01/16 02:21 下午
     **/

    @Override
    public Result<List<LazyNettyServerPermeatePortPool>> batchStory(List<LazyNettyServerPermeatePortPoolStoryCommand> lazyNettyServerPermeatePortPoolStoryCommandList) {
        List<LazyNettyServerPermeatePortPool> lazyNettyServerPermeatePortPoolList = lazyNettyServerPermeatePortPoolStoryCommandList
                .stream()
                .map(NettyServerVisitorDTOAssembler.INSTANCE::toNettyServerVisitor
                )
                .collect(Collectors.toList());
        return lazyNettyServerPermeatePortPoolRepository.batchStory(lazyNettyServerPermeatePortPoolList);
    }

    /**
     * describe 更新服务端提前开放出来的端口
     *
     * @param lazyNettyServerPermeatePortPoolUpdateCommand 更新服务端提前开放出来的端口
     * @return {@link Result<  LazyNettyServerPermeatePortPool  >} 服务端提前开放出来的端口领域对象
     * @author Jia wei Wu
     * @date 2024/01/16 02:21 下午
     **/

    @Override
    public Result<LazyNettyServerPermeatePortPool> updateOne(LazyNettyServerPermeatePortPoolUpdateCommand lazyNettyServerPermeatePortPoolUpdateCommand) {
        LazyNettyServerPermeatePortPool lazyNettyServerPermeatePortPool = NettyServerVisitorDTOAssembler.INSTANCE.toNettyServerVisitor(lazyNettyServerPermeatePortPoolUpdateCommand);
        return lazyNettyServerPermeatePortPoolRepository.story(lazyNettyServerPermeatePortPool);
    }

    /**
     * describe 查询单个服务端提前开放出来的端口
     *
     * @param lazyNettyServerPermeatePortPoolQueryOneCommand 查询单个服务端提前开放出来的端口
     * @return {@link Result<  LazyNettyServerVisitorDTO  >} 服务端提前开放出来的端口DTO对象
     * @author Jia wei Wu
     * @date 2024/01/16 02:21 下午
     **/

    @Override
    public Result<LazyNettyServerVisitorDTO> findOne(LazyNettyServerPermeatePortPoolQueryOneCommand lazyNettyServerPermeatePortPoolQueryOneCommand) {
        LazyNettyServerPermeatePortPool lazyNettyServerPermeatePortPool = NettyServerVisitorDTOAssembler.INSTANCE.toNettyServerVisitor(lazyNettyServerPermeatePortPoolQueryOneCommand);
        return lazyNettyServerPermeatePortPoolRepository.findOne(lazyNettyServerPermeatePortPool).convert(NettyServerVisitorDTOAssembler.INSTANCE::fromNettyServerVisitor);
    }

    /**
     * describe 查询多个服务端提前开放出来的端口
     *
     * @param lazyNettyServerPermeatePortPoolQueryListCommand 查询多个服务端提前开放出来的端口
     * @return {@link Result<List< LazyNettyServerVisitorDTO >>} 服务端提前开放出来的端口DTO对象
     * @author Jia wei Wu
     * @date 2024/01/16 02:21 下午
     **/

    @Override
    public Result<List<LazyNettyServerVisitorDTO>> findList(LazyNettyServerPermeatePortPoolQueryListCommand lazyNettyServerPermeatePortPoolQueryListCommand) {
        LazyNettyServerPermeatePortPool lazyNettyServerPermeatePortPool = NettyServerVisitorDTOAssembler.INSTANCE.toNettyServerVisitor(lazyNettyServerPermeatePortPoolQueryListCommand);
        return lazyNettyServerPermeatePortPoolRepository.findList(lazyNettyServerPermeatePortPool).convert(nettyServerVisitors -> nettyServerVisitors.stream().map(NettyServerVisitorDTOAssembler.INSTANCE::fromNettyServerVisitor).collect(Collectors.toList()));
    }

    /**
     * describe 分页查询多个服务端提前开放出来的端口
     *
     * @param lazyNettyServerPermeatePortPoolQueryListCommand 分页查询多个服务端提前开放出来的端口
     * @return {@link Result<LazyPage< LazyNettyServerVisitorDTO >>} 分页服务端提前开放出来的端口DTO对象
     * @author Jia wei Wu
     * @date 2024/01/16 02:21 下午
     **/

    @Override
    public Result<LazyPage<LazyNettyServerVisitorDTO>> findPage(int size, int current, LazyNettyServerPermeatePortPoolQueryListCommand lazyNettyServerPermeatePortPoolQueryListCommand) {
        LazyNettyServerPermeatePortPool lazyNettyServerPermeatePortPool = NettyServerVisitorDTOAssembler.INSTANCE.toNettyServerVisitor(lazyNettyServerPermeatePortPoolQueryListCommand);
        return lazyNettyServerPermeatePortPoolRepository.findPage(size, current, lazyNettyServerPermeatePortPool).convert(page -> page.convert(NettyServerVisitorDTOAssembler.INSTANCE::fromNettyServerVisitor));
    }

    /**
     * describe 删除服务端提前开放出来的端口
     *
     * @param lazyNettyServerPermeatePortPoolRemoveCommand 删除服务端提前开放出来的端口
     * @return {@link Result<  LazyNettyServerPermeatePortPool  >} 服务端提前开放出来的端口
     * @author Jia wei Wu
     * @date 2024/01/16 02:21 下午
     **/

    @Override
    public Result<LazyNettyServerPermeatePortPool> remove(LazyNettyServerPermeatePortPoolRemoveCommand lazyNettyServerPermeatePortPoolRemoveCommand) {
        LazyNettyServerPermeatePortPool lazyNettyServerPermeatePortPool = NettyServerVisitorDTOAssembler.INSTANCE.toNettyServerVisitor(lazyNettyServerPermeatePortPoolRemoveCommand);
        return lazyNettyServerPermeatePortPoolRepository.remove(lazyNettyServerPermeatePortPool);
    }

}